package com.jinmdz.fmis.dao.dao.provider;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;


/**
 * 火化Provider
 *
 * @author LiCongLu
 * @date 2020-02-16 16:29
 */
public class CremationProvider {

    /**
     * 按照业务编码查询火化信息
     *
     * @param id 主键
     * @return
     * @author LiCongLu
     * @date 2020-02-20 15:08
     */
    public String getCremationViewById(@Param("id") Integer id) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" cremation.id,cremation.business_code,cremation.furnace_type_code,furnace_id");
                builder.append(" ,as_appointment,appointment_date,appointment_time_segment");
                builder.append(" ,reality_start_time,reality_cooling_time,reality_finish_time,cremation_no ");
                builder.append(" ,process_state_code,as_active,rule_number,rule_unit,rule_code,rule_remark,cremation.remark,cremation.random_code ");
                builder.append(" ,charge_id,as_take_ash,cremation.ash_handle_type_code,ash_whereabouts_code,cremation.version ");
                builder.append(" ,cremation_furnace.furnace_code ");
                builder.append(" ,funeral_dead.cremation_type_code");
                SELECT(builder.toString());
                FROM(" cremation ");
                JOIN(" funeral_dead on funeral_dead.business_code = cremation.business_code ");
                LEFT_OUTER_JOIN(" cremation_furnace on cremation_furnace.id = cremation.furnace_id  ");
                WHERE(" cremation.deleted = 0 ");
                WHERE(" cremation.id = #{id} ");
                ORDER_BY(" cremation.id ");
            }
        }.toString();
    }

    /**
     * 按照业务编码查询火化信息
     *
     * @param businessCode 业务编码
     * @return
     * @author LiCongLu
     * @date 2020-02-16 16:29
     */
    public String listCremationViewByBusinessCode(@Param("businessCode") String businessCode) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" cremation.id,cremation.business_code,cremation.furnace_type_code,furnace_id");
                builder.append(" ,as_appointment,appointment_date,appointment_time_segment");
                builder.append(" ,reality_start_time,reality_cooling_time,reality_finish_time,cremation_no ");
                builder.append(" ,process_state_code,as_active,rule_number,rule_unit,rule_code,rule_remark,cremation.remark,cremation.random_code ");
                builder.append(" ,charge_id,as_take_ash,cremation.ash_handle_type_code,ash_whereabouts_code,cremation.version ");
                builder.append(" ,cremation_furnace.furnace_code ");
                builder.append(" ,funeral_dead.cremation_type_code");
                SELECT(builder.toString());
                FROM(" cremation ");
                JOIN(" funeral_dead on funeral_dead.business_code = cremation.business_code ");
                LEFT_OUTER_JOIN(" cremation_furnace on cremation_furnace.id = cremation.furnace_id  ");
                WHERE(" cremation.deleted = 0 ");
                WHERE(" cremation.business_code = #{businessCode} ");
                ORDER_BY(" cremation.id ");
            }
        }.toString();
    }


    /**
     * 按照业务编码查询火化信息
     *
     * @param businessCode 业务编码
     * @return
     * @author GuanKui
     * @date 2020/2/21 14:59
     */

    public String getCremationViewAsActiveByBusinessCode(@Param("businessCode") String businessCode) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" cremation.id,cremation.business_code,cremation.furnace_type_code,furnace_id");
                builder.append(" ,as_appointment,appointment_date,appointment_time_segment");
                builder.append(" ,reality_start_time,reality_cooling_time,reality_finish_time,cremation_no ");
                builder.append(" ,process_state_code,as_active,rule_number,rule_unit,rule_code,rule_remark,cremation.remark,cremation.random_code ");
                builder.append(" ,charge_id,as_take_ash,cremation.ash_handle_type_code,ash_whereabouts_code,cremation.version ");
                builder.append(" ,cremation_furnace.furnace_code ");
                builder.append(" ,funeral_dead.cremation_type_code");
                SELECT(builder.toString());
                FROM(" cremation ");
                LEFT_OUTER_JOIN(" cremation_furnace on cremation_furnace.id = cremation.furnace_id  ");
                LEFT_OUTER_JOIN(" funeral_dead on funeral_dead.business_code = cremation.business_code ");
                WHERE(" cremation.deleted = 0 and cremation.as_active = 1 ");
                WHERE(" cremation.business_code = #{businessCode} ");
                ORDER_BY(" cremation.id limit 1");

            }
        }.toString();
    }
}
